package com.zihan.controller;


import com.zihan.domain.dto.ActivityDTO;
import com.zihan.domain.entity.Activity;
import com.zihan.domain.result.PageResult;
import com.zihan.domain.result.Result;
import com.zihan.domain.vo.ActivityVO;
import com.zihan.service.IActivityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 学术活动表 前端控制器
 * </p>
 *
 * @author zhangzihan
 * @since 2025-10-17
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Resource
    private IActivityService activityService;

    /**
     * 获取所有的活动列表
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult> list(ActivityDTO activityDTO) {
        return activityService.getList(activityDTO);
    }


    /**
     * 获取当前教师用户的活动列表
     */
    @GetMapping("/getCurrent/list")
    public Result<PageResult> getCurrentList(ActivityDTO activityDTO) {
        return activityService.getCurrentTeacherList(activityDTO);
    }



    @PostMapping("/publish")
    public Result<String> addActivity(@RequestBody Activity activity) {
        return activityService.addActivity(activity);
    }


    // 查看活动详情
    @GetMapping("/detail/{id}")
    public Result<ActivityVO> detail(@PathVariable Long id) {
        return activityService.detail(id);
    }


    // 更新活动
    @PutMapping("/update")
    public Result<String> updateActivity(@RequestBody Activity activity) {
        return activityService.updateActivity(activity);
    }


    // 删除活动（逻辑删除）
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteActivity(@PathVariable Long id) {
        return activityService.deleteActivity(id);
    }


    // 报名活动
    @PostMapping("/signUp/{id}")
    public Result<String> signUp(@PathVariable Long id) {
        return activityService.signUp(id);
    }


    // 取消报名
    @PutMapping("/cancelSignUp/{id}")
    public Result<String> cancelSignUp(@PathVariable Long id) {
        return activityService.cancelSignUp(id);
    }


    //导出活动参与者列表
    @GetMapping("/export/participate/{activity}")
    public void exportAnticipate(@PathVariable Long  activity, HttpServletResponse response) throws IOException {
        activityService.exportAnticipate(activity,response);
    }


    // 学生查询已经参与的活动信息
    @GetMapping("/getStudent/list")
    public Result<PageResult> getStudentList(ActivityDTO activityDTO) {
        return activityService.getStudentList(activityDTO);
    }

    // 签到
    @PostMapping("/checkIn/{id}")
    public Result<String> checkIn(@PathVariable Long id) {
        return activityService.checkIn(id);
    }
}
